<?php
namespace Sys\Controller;
use Sys\Controller\BasetwoController;

class TeacherController extends BasetwoController{

    public function index(){
        $this->checkTeacherLogin();
        $User = M('teachers');//实例化User对象
        //进行分页数据查询 注意page方法的参数的前面部分是当前的页数使用$_GET[p]获取
        $list = $User->page($_GET['p'],'10')->select();
        $this->assign('navs',$list);// 赋值数据集
        $count= $User->count();// 查询满足要求的总记录数
        $Page= new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        $Page -> setConfig('header','<span class="rows">共<b>%TOTAL_ROW%</b>条记录 第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</span>');
        $Page -> setConfig('prev', '上一页');
        $Page -> setConfig('next','下一页');
        $Page -> setConfig('last','末页');
        $Page -> setConfig('first','首页');
        $Page -> setConfig('theme','%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
        $show= $Page->show();// 分页显示输出
        $this->assign('page',$show);// 赋值分页输出
        $this->display();
    }


    //删除老师
    public function doDelTeacher(){
        $where= I('post.ids');
        M('teachers')->delete($where);
    }

    //修改老师
    public function doEditTeacher(){
        $res=D('teachers');
        if ($res->create()){
            $res->save();
        }else{
            echo '修改失败';
        }
    }

    //添加老师
    public function doAddTeacher(){
        M('teachers')->create();
        if(M('teachers')->add()){
            $a=U('index');
            header("location:{$a}");

        };
    }
}